package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车相关接口")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("购物车添加商品")
    public Result addShop(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.addShopping(shoppingCartDTO);

        return Result.success();
    }

    @GetMapping("/list")
    public Result cartList() {
        //无需请求参数，只需要获得当前用户id即可了
        List<ShoppingCart> shoppingCartList = shoppingCartService.showShopCart();
        return Result.success(shoppingCartList);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result cleanCart() {
        shoppingCartService.clean();
        return Result.success();
    }

    @PostMapping("/sub")
    @ApiOperation("购物车删除商品功能")

    public Result subShop(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.subShop(shoppingCartDTO);
        return Result.success();
    }
}
